<template>
  <div></div>
</template>

<script setup lang="ts">
  import { PrismaClient } from '@prisma/client'

  const prisma = new PrismaClient()

  async function main() {
    // 新增数据
    /* const user = await prisma.user.create({
      data: {
        username: 'kunkun',
        age: 18,
        userType: 'user',
        sort: 10,
        email: 'ikun@qq.com'
      }
    }) */
    /* const user = await prisma.user.create({
      data: {
        username: '唔西迪西',
        age: 20,
        userType: 'user',
        sort: 12,
        email: 'wuidxi@qq.com'
      }
    }) */
    /* const user = await prisma.user.create({
      data: {
        username: '玛卡巴卡',
        age: 25,
        userType: 'admin',
        sort: 14,
        email: 'makabaka@qq.com',
        posts: {
          create: [
            {
              title: '标题1',
              content: '内容1',
              published: true
            },
            {
              title: '标题2',
              content: '内容2',
              published: false
            }
          ]
        }
      }
    }) */
    // 删除数据
    /* const user = await prisma.user.delete({
      where: {
        id: 2
      }
    }) */
    // 更新数据
    /* const user = await prisma.user.update({
      where: {
        id: 1
      },
      data: {
        username: '坤坤',
        userType: 'admin'
      }
    }) */
    // console.log(user)
    // 查询数据
    // const users = await prisma.user.findMany()
    // console.log(users)
    // 根据条件查询
    // const foundUser = await prisma.user.findUnique({ where: { id: 1 } })
    // 关联查询
    // const foundUser = await prisma.user.findUnique({
    //   where: {
    //     id: 3
    //   },
    //   // 关联查询该用户的 posts
    //   include: {
    //     posts: true
    //   }
    // })
    // console.log(foundUser)
  }

  main()
</script>

<style scoped></style>
